﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CardLogistics.Web.Controls
{

    public partial class WebUserControl_ToolBar : System.Web.UI.UserControl
    {

        /// <summary>
        /// 添加页面URL
        /// </summary>
        public string AddUrl
        {
            get;
            set;
        }
        /// <summary>
        /// 当前页面菜单id
        /// </summary>
        public string MenuId
        {
            get;
            set;
        }
        /// <summary>
        /// 当前菜单名称
        /// </summary>
        public string MenuName
        {
            get;
            set;
        }
        /// <summary>
        /// 审批页面地址
        /// </summary>
        public string AppUrl
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            MenuId = Request.QueryString["mid"];
            //MenuName = "kong";
            if (!IsPostBack)
                LoadBtn(MenuId);
        }


        #region 添加
        protected void btn_Add_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(AddUrl))
                Response.Redirect(AddUrl);
            else
                Response.Redirect("AddEdit.aspx?type=add&mid=" + Request.QueryString["mid"]);
        }
        #endregion

        //定义编辑事件
        #region 删除事件
        public event EventHandler DeleteEvent;
        protected void btn_Delete_Click(object sender, EventArgs e)
        {
            if (DeleteEvent != null)
            {
                DeleteEvent(this, EventArgs.Empty);
            }
        }
        #endregion


        #region 权限按钮控制
        /// <summary>
        /// 按钮权限控制
        /// </summary>
        /// <param name="mIdbtnPar">菜单id</param>
        private void LoadBtn(string mIdbtnPar)
        {
            if (!string.IsNullOrEmpty(mIdbtnPar))
            {
                DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(" select t.menuid,t.parentid,t.menuname from sys_menus t where t.parentid=" + mIdbtnPar + "  ");
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["menuname"].ToString() == "新增")
                            btn_Add.Visible = true;
                        if (dr["menuname"].ToString() == "修改")
                            d_Edit.Visible = true;
                        if (dr["menuname"].ToString() == "删除")
                            btn_Delete.Visible = true;
                        if (dr["menuname"].ToString() == "详情")
                            d_Detail.Visible = true;
                        if (dr["menuname"].ToString() == "审批")
                            this.d_App.Visible = true;
                        if (dr["menuname"].ToString() == "导出")
                            this.d_Exp.Visible = true;

                    }
                }
            }
        }
        #endregion

       
        //定义编辑事件
        #region 导出事件 暂时未用
        public event EventHandler ExportEvent;
        protected void btnExport_Click(object sender, EventArgs e)
        {
            if (ExportEvent != null)
            {
                ExportEvent(this, EventArgs.Empty);
            }
        }
        #endregion
    }
}